package org.zjx;

import lombok.SneakyThrows;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.zjx.service.RouteService;
import org.zjx.service.ScreenService;
import org.zjx.service.impl.RouteServiceImpl;
import org.zjx.service.impl.ScreenServiceImpl;

public class Main {
    @SneakyThrows
    public static void main(String[] args) {

        ApplicationConfig applicationConfig = new ApplicationConfig("sample-provider");
        applicationConfig.setSerializeCheckStatus("DISABLE");

        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(23134);
        protocolConfig.setSerialization("fastjson2"); // 强制使用FastJSON序列化

        RegistryConfig registryConfig = new RegistryConfig(RegistryConfig.NO_AVAILABLE);

        // 2. 暴露 UserService
        ServiceConfig<RouteService> routeServiceServiceConfig = new ServiceConfig<>();
        routeServiceServiceConfig.setInterface(RouteService.class);
        routeServiceServiceConfig.setRef(new RouteServiceImpl());
        routeServiceServiceConfig.setRegistry(registryConfig);
        routeServiceServiceConfig.setProtocol(protocolConfig);
        routeServiceServiceConfig.setApplication(applicationConfig);
        routeServiceServiceConfig.export();


        // 3. 暴露 OrderService
        ServiceConfig<ScreenService> orderServiceConfig = new ServiceConfig<>();
        orderServiceConfig.setInterface(ScreenService.class);
        orderServiceConfig.setRef(new ScreenServiceImpl());
        orderServiceConfig.setRegistry(registryConfig);
        orderServiceConfig.setProtocol(protocolConfig);
        orderServiceConfig.setApplication(applicationConfig);
        orderServiceConfig.export();

//
//
//        // 3. 暴露 OrderService
//        ServiceConfig<PropService> propServiceConfig = new ServiceConfig<>();
//        propServiceConfig.setInterface(PropService.class);
//        propServiceConfig.setRef(new PropServiceImpl());
//        propServiceConfig.setRegistry(registryConfig);
//        propServiceConfig.setProtocol(protocolConfig);
//        propServiceConfig.setApplication(applicationConfig);
//        propServiceConfig.export();

        System.out.println("UserService,OrderService,PropService 和 RouteService 已暴露,使用序列化协议: " + protocolConfig.getSerialization());

        System.in.read(); // 阻塞主线程
    }
}